/*

Replication code for Ben Cormier, "Partisan External Borrowing in Middle Income Countries," forthcoming, 
British Journal of Political Science. 

Note: requires estout package

*/


**************
*Data and set*
**************
use "Post1989MICs_VarsUsedOnly.dta", clear
encode CountryCode, gen(country_num) 
tsset country_num year





***************************************************************
*Table 1 & Figure 3 (Class constituency models using V-Party)*
***************************************************************


*m1 Correlation
regress DV_COMM_New_PERMarket_LEAD Party_UrbAndRuralWorkingAndMid, robust
estimates store m1

*m2 Full FE Model
regress DV_COMM_New_PERMarket_LEAD Party_UrbAndRuralWorkingAndMid DV_COMM_New_PERMarket Crtg_BestOf annavg_UStrasuryIntRate GNIgrowth_AnnPer Inflation FiscalRevMINUSExp_LEAD Crisis PPGDebtService_PerGNI Reserves_PerTotalExternalDebt ///
v2x_regime v2x_rule v2xcl_prpty YrsTilElection_LEAD UNagreeWithUSA_2020 UNagreeWithChina_2020 i.year i.country_num, robust
estimates store m2

*m3 GMM
xtabond2 DV_COMM_New_PERMarket_LEAD Party_UrbAndRuralWorkingAndMid DV_COMM_New_PERMarket Crtg_BestOf annavg_UStrasuryIntRate GNIgrowth_AnnPer Inflation FiscalRevMINUSExp_LEAD Crisis PPGDebtService_PerGNI Reserves_PerTotalExternalDebt ///
v2x_regime v2x_rule v2xcl_prpty YrsTilElection_LEAD UNagreeWithUSA_2020 UNagreeWithChina_2020, robust orthogonal ///
gmm(l.Party_UrbAndRuralWorkingAndMid l.DV_COMM_New_PERMarket, laglimits(. 4) collapse) ///
iv (Crtg_BestOf annavg_UStrasuryIntRate GNIgrowth_AnnPer Inflation FiscalRevMINUSExp_LEAD Crisis PPGDebtService_PerGNI Reserves_PerTotalExternalDebt v2x_regime v2x_rule v2xcl_prpty YrsTilElection_LEAD UNagreeWithUSA_2020 UNagreeWithChina_2020)
estimates store m3

*m4 Fractioned Probit
fracreg probit DV_COMM_New_PERMarket_LEAD Party_UrbAndRuralWorkingAndMid DV_COMM_New_PERMarket Crtg_BestOf annavg_UStrasuryIntRate GNIgrowth_AnnPer Inflation FiscalRevMINUSExp_LEAD Crisis PPGDebtService_PerGNI Reserves_PerTotalExternalDebt ///
v2x_regime v2x_rule v2xcl_prpty YrsTilElection_LEAD UNagreeWithUSA_2020 UNagreeWithChina_2020 i.year, vce(cluster country_num)
estimates store m4

*m5 Fractioned Logit
fracreg logit DV_COMM_New_PERMarket_LEAD Party_UrbAndRuralWorkingAndMid DV_COMM_New_PERMarket Crtg_BestOf annavg_UStrasuryIntRate GNIgrowth_AnnPer Inflation FiscalRevMINUSExp_LEAD Crisis PPGDebtService_PerGNI Reserves_PerTotalExternalDebt ///
v2x_regime v2x_rule v2xcl_prpty YrsTilElection_LEAD UNagreeWithUSA_2020 UNagreeWithChina_2020 i.year, vce(cluster country_num)
estimates store m5

*Table 1
esttab m1 m2 m3 m4 m5, /// 
varlabels("Party_UrbAndRuralWorkingAndMid" "WorkingPoorPrty" "DV_COMM_New_PERMarket" "DVlag" "Crtg_BestOf" "CreditRating" "annavg_UStrasuryIntRate" "USIrates" "GNIpercap_CurrUSD" "GNI" "GNIgrowth_AnnPer" "Growth" "FiscalRevMINUSExp_LEAD" "Deficit" "PPGDebtService_PerGNI" "DebtService" ///
"ShortTermDebt_PerofReserves" "Short-TermDebt" "Reserves_PerTotalExternalDebt" "Reserves" "DomesticCredit_PerGDP" "DomesticCredit" "v2x_regime" "Democracy" "v2x_rule" "RuleOfLaw" "v2xcl_prpty" "PropRights" "YrsTilElection_LEAD" "PolCycle" ///
"UNagreeWithUSA_2020" "UN_USalign" "UNagreeWithChina_2020" "UN_CHNalign") ///
collabels(none) mgroups("OLS" "GMM" "Fractioned" "Nested Random Effects", pattern (1 0 1 1 0 1 0 0 0)) ///
cells(b(star fmt(%9.3f)) se(par)) stats(N) starlevels(* 0.1 ** 0.05 *** 0.01) nonumbers legend /// 
title("Table 1: Modeling the Effect of Labor & Poor on MIC External Borrowing") /// 
note("Robust SEs in FE OLS models and GMM" "Cluster-Robust SEs in Fractional Models" "GMM instruments collapsed (instruments < No. of countries) and orthogonal (rather than first difference at every gap in data)" ///
"Dependent Variable, Deficit, and PolCycle led one year (see DGP discussion in text)")

*Figure 3
fracreg logit DV_COMM_New_PERMarket_LEAD Party_UrbAndRuralWorkingAndMid DV_COMM_New_PERMarket Crtg_BestOf annavg_UStrasuryIntRate GNIgrowth_AnnPer Inflation FiscalRevMINUSExp_LEAD Crisis PPGDebtService_PerGNI Reserves_PerTotalExternalDebt ///
v2x_regime v2x_rule v2xcl_prpty YrsTilElection_LEAD UNagreeWithUSA_2020 UNagreeWithChina_2020 i.year, vce(cluster country_num)
predict yhatDVPerMktFinance
grstyle init
grstyle set plain, nogrid
twoway lfitci yhatDVPerMktFinance Party_UrbAndRuralWorkingAndMid, ///
	ciplot(rline) alcolor(black) alpattern(dash) fcolor(none) ///
	ytitle("% Borrowed From Markets") ytitle(, size(small)) ylabel(,labsize(small)) ///
	xtitle("Strength of Working Classes & Poor in Governing Party's Constitutency (WorkingPoorPrty)") xtitle(, size(small)) xlabel(,labsize(small)) ///
	legend(off) title("Fig. 3: Predicted Marginal Effect of Working Class & Poor Constituencies on MIC Market Use") title(, size(small)) ///
	note("Model 5 in Table 1 with robust errors clustered on country" "95% Confidence Interval", size(small))

	
	
	
	
***************************************************************
*Table 2 & Figure 4 (Left-Right models using DPI)*
***************************************************************
*Drop observations not coded as Right or Left
drop if CondMeanGroups_1R_2LC_0NA==0
drop if Center==1
	
*dpim1 Correlation
regress DV_COMM_New_PERMarket_LEAD i.Left, robust
estimates store dpim1
margins, dydx(i.Left) atmeans
estimates store Model1

*dpim2 Full FE Model
regress DV_COMM_New_PERMarket_LEAD i.Left DV_COMM_New_PERMarket Crtg_BestOf annavg_UStrasuryIntRate GNIgrowth_AnnPer Inflation FiscalRevMINUSExp_LEAD Crisis PPGDebtService_PerGNI Reserves_PerTotalExternalDebt ///
v2x_regime v2x_rule v2xcl_prpty YrsTilElection_LEAD UNagreeWithUSA_2020 UNagreeWithChina_2020 i.year i.country_num, robust
estimates store dpim2
margins, dydx(i.Left) atmeans
estimates store Model2

*dpim3 GMM
xtabond2 DV_COMM_New_PERMarket_LEAD i.Left DV_COMM_New_PERMarket Crtg_BestOf annavg_UStrasuryIntRate GNIgrowth_AnnPer Inflation FiscalRevMINUSExp_LEAD Crisis PPGDebtService_PerGNI Reserves_PerTotalExternalDebt ///
v2x_regime v2x_rule v2xcl_prpty YrsTilElection_LEAD UNagreeWithUSA_2020 UNagreeWithChina_2020, robust orthogonal ///
gmm(l.Left l.DV_COMM_New_PERMarket, laglimits(. 4) collapse) ///
iv (Crtg_BestOf annavg_UStrasuryIntRate GNIgrowth_AnnPer Inflation FiscalRevMINUSExp_LEAD Crisis PPGDebtService_PerGNI Reserves_PerTotalExternalDebt v2x_regime v2x_rule v2xcl_prpty YrsTilElection_LEAD UNagreeWithUSA_2020 UNagreeWithChina_2020)
estimates store dpim3
margins, dydx(i.Left) atmeans
estimates store Model3

*dpim4 Fractioned Probit
fracreg probit DV_COMM_New_PERMarket_LEAD i.Left DV_COMM_New_PERMarket Crtg_BestOf annavg_UStrasuryIntRate GNIgrowth_AnnPer Inflation FiscalRevMINUSExp_LEAD Crisis PPGDebtService_PerGNI Reserves_PerTotalExternalDebt ///
v2x_regime v2x_rule v2xcl_prpty YrsTilElection_LEAD UNagreeWithUSA_2020 UNagreeWithChina_2020 i.year, vce(cluster country_num)
estimates store dpim4
margins, dydx(i.Left) atmeans
estimates store Model4

*dpim4 Fractioned Logit
fracreg logit DV_COMM_New_PERMarket_LEAD i.Left DV_COMM_New_PERMarket Crtg_BestOf annavg_UStrasuryIntRate GNIgrowth_AnnPer Inflation FiscalRevMINUSExp_LEAD Crisis PPGDebtService_PerGNI Reserves_PerTotalExternalDebt ///
v2x_regime v2x_rule v2xcl_prpty YrsTilElection_LEAD UNagreeWithUSA_2020 UNagreeWithChina_2020 i.year, vce(cluster country_num)
estimates store dpim5
margins, dydx(i.Left) atmeans
estimates store Model5

*Table 2
*Table
esttab dpim1 dpim2 dpim3 dpim4 dpim5, /// 
varlabels("Left" "Left" "DV_COMM_New_PERMarket" "DVlag" "Crtg_BestOf" "CreditRating" "annavg_UStrasuryIntRate" "USIrates" "GNIpercap_CurrUSD" "GNI" "GNIgrowth_AnnPer" "Growth" "FiscalRevMINUSExp_LEAD" "Deficit" "PPGDebtService_PerGNI" "DebtService" ///
"ShortTermDebt_PerofReserves" "Short-TermDebt" "Reserves_PerTotalExternalDebt" "Reserves" "DomesticCredit_PerGDP" "DomesticCredit" "v2x_regime" "Democracy" "v2x_rule" "RuleOfLaw" "v2xcl_prpty" "PropRights" "YrsTilElection_LEAD" "PolCycle" ///
"UNagreeWithUSA_2020" "UN_USalign" "UNagreeWithChina_2020" "UN_CHNalign") ///
collabels(none) mgroups("OLS" "GMM" "Fractioned" "Nested Random Effects", pattern (1 0 1 1 0 1 0 0 0)) ///
cells(b(star fmt(%9.3f)) se(par)) stats(N) starlevels(* 0.1 ** 0.05 *** 0.01) nonumbers legend /// 
title("Table 2: Modeling the Left-Right Partisan Effect on MIC External Borrowing") /// 
note("Robust SEs in FE OLS models and GMM" "Cluster-Robust SEs in Hierarchical Models" "GMM instruments collapsed (instruments < No. of countries) and orthogonal (rather than first difference at every gap in data)" ///
"Dependent Variable, Deficit, and PolCycle led one year (see DGP discussion in text)")

*Figure 4
set scheme s1mono
grstyle init
grstyle set plain, nogrid 
coefplot Model1 Model2 Model3 Model4 Model5, keep(*Left) ytitle("% Borrowed From Markets") ///
ylabel(,nogrid) xlabel(1 "Left", tlength(0) nogrid) xscale(lstyle(none)) ///
vertical yline(0, lc(black)) mcolor(mono) legend(rows(1) span size(small)) levels(95) ///
title("Fig. 4: Average Marginal Effect of Left Partisanship on MIC Market Use", size(small)) note("95% confidence intervals" "Other covariates held to means", size(small))

	
	
	
	
	
	
